<template>
	<view>
		<view class="row-box row-form" v-if="list && list.length>0">
			<view class="row-border" v-for="(item,index) in list" :key="index">
				<view class='row-cell' v-if="item.attr_type=='text'">
					<p-check-text @change="checkRuleChange" v-model="list[index].value" :field="item.attr_name" :textClass="item.required?'required':'not-required'" :tip="item.placeholder || item.attr_name+'未填写'">{{item.attr_name}}</p-check-text>
					<view class="right">
						<input v-model="list[index].value" @change="onChange" :placeholder="item.placeholder"  placeholder-class="tips"/>
						<text class="margin-left" v-if="item.attr_unit">{{item.attr_unit}}</text>
					</view>	
				</view>
				<view class='row-cell' v-if="item.attr_type=='label'">
					<p-check-text @change="checkRuleChange" v-model="list[index].value" :field="item.attr_name" :textClass="item.required?'required':'not-required'" :tip="item.placeholder || item.attr_name+'未填写'">{{item.attr_name}}</p-check-text>
					<view>
						<text class="margin-left" v-if="item.attr_unit">{{item.placeholder}}</text>
					</view>	
				</view>
				<view class='row-cell' v-if="item.attr_type=='number'">
					<p-check-text @change="checkRuleChange" v-model="list[index].value" :field="item.attr_name" :textClass="item.required?'required':'not-required'" :tip="item.placeholder || item.attr_name+'未填写'">{{item.attr_name}}</p-check-text>
					<view class="right">
						<uni-number-box v-model="list[index].value" :min="0" @change="onChange"/>
						<text class="margin-left" v-if="item.attr_unit">{{item.attr_unit}}</text>
					</view>	
				</view>
				<view class='row-cell row-col' v-else-if="item.attr_type=='textarea'">
					<p-check-text @change="checkRuleChange" v-model="list[index].value" :field="item.attr_name" :textClass="item.required?'required':'not-required'" :tip="item.placeholder || item.attr_name+'未填写'">{{item.attr_name}}</p-check-text>
					<view class="padding-bottom-10">
						<p-text-area v-model="list[index].value" :placeholder="item.placeholder" placeholder-class="tips" @change="onChange"></p-text-area>
						
					</view>				
				</view>
				<view class='row-cell row-col' v-else-if="item.attr_type=='image'">
					<p-check-text @change="checkRuleChange" v-model="list[index].value" :field="item.attr_name" :textClass="item.required?'required':'not-required'" :tip="item.placeholder || item.attr_name+'未上传'">{{item.attr_name}}</p-check-text>
					<view class="padding-left-10">
						<p-input-upload v-model="list[index].value" @change="onChange" :upload_count="1" mode="image"></p-input-upload>
					</view>	
				</view>
				<view class='row-cell' v-else-if="'radio,select,checkbox,radio_button,check_buttton'.indexOf(item.attr_type)>=0">
					<p-check-text @change="checkRuleChange" v-model="list[index].value" :field="item.attr_name" :textClass="item.required?'required':'not-required'" :tip="item.placeholder || '请选择'+item.attr_name">{{item.attr_name}}</p-check-text>
					<view class="right" @click="open('popup_'+item.id)" >
						<text v-if="item.value">{{item.value}}</text>
						<text v-else class="tip">请选择{{item.attr_name}}</text>
						<uni-icons type="arrowright" size="20" color='#ccc'></uni-icons>
					</view>	
				</view>
			</view>
			<view v-for="(item,index) in list" :key="index">
				<p-popup-sheet v-if="'radio,select,checkbox,radio_button,check_buttton'.indexOf(item.attr_type)>=0" :ref="'popup_'+item.id" v-model="list[index].value" :list="item.values" :column="1" :type="item.attr_type" :okTitle="item.attr_type.indexOf('check')>=0?'确认':''" returnType="name" @change="onChange"></p-popup-sheet>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: [Array,Object],
				default () {
					return {}
				}
			},
		},
		data() {
			return {

			}
		},
		created() {
			
		},
		mounted() {
			
	
		},

		methods: {
			onChange(){
				this.$emit('input', this.list);
				this.$emit('change', this.list);
			},
			getValues(){
				let values = {};
				for (var i = 0; i < this.list.length; i++) {
					let item = this.list[i];
					values[item.attr_code?item.attr_code:item.attr_name] = item.value;
				}
				return values;			
			},
			check(){
				return this.validator.check(this.ruleList,this.list);
								
			},
			
		
		}
	}
</script>

